package com.coco.goods.controller;

import com.coco.goods.pojo.TbSpecs;
import com.coco.goods.service.SpecsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author minicoco
 * @version 1.0
 * @date 2021/7/16 20:37
 */
@RestController
@RequestMapping("/specs")
public class SpecsController {

    @Autowired
    private SpecsService specsService;

    /**
     * 查询商品规格信息 包含规格值
     * @return
     */
    @GetMapping("/findSpecList")
    public List<TbSpecs> findSpecList(String name){
        return specsService.findSpecList(name);
    }

    /**
     * 添加商品规格属性
     * @param specs
     */
    @PostMapping("/addSpecs")
    public void addSpecs( @RequestBody TbSpecs specs){
        specsService.addSpecs(specs);
    }


    @GetMapping("/findSpecsById/{id}")
    public TbSpecs findSpecsById(@PathVariable("id") Long id){
        return specsService.findSpecsById(id);
    }

    /**
     * 修改商品规格
     * @param specs
     */
    @PutMapping("/updateSpecs/{id}")
    public void updateSpecs(@RequestBody TbSpecs specs,@PathVariable Long id){
        if (id==null){
            specsService.addSpecs(specs);
        }
        specs.setId(id);
        specsService.updateSpecs(specs);
    }


    /**
     * 批量删除商品规格
     * @param ids
     */
    @DeleteMapping("/deleteSpecs")
    public void deleteSpecs(@RequestParam("ids") Long[] ids){
        specsService.deleteSpecs(ids);
    }

}
